﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Process;

namespace ObjectManager
{
    public class DangKy : ManagerComponent
    {
        private DangKyDAO DangKyDAO { get; set; }

        public List<DangKyDTO> DanhSach { get; set; }

        private void Initialize()
        {
            DanhSach = new List<DangKyDTO>();
            DangKyDAO = new DangKyDAO();
        }

        public DangKy()
        {
            Initialize();
        }
    
        public override int Add()
        {
            int count = 0;
            if (DanhSach.Count > 0)
            {
                for (int i = 0; i < DanhSach.Count; i++)
                {
                    DangKyDAO.DangKyDTO = DanhSach[i];
                    if (DangKyDAO.Insert() > 0)
                    {
                        count++;
                    }
                }
            }
            if (count > 0)
            {
                return count;
            }
            return -1;
        }

        public override int Update()
        {
            return -1;
        }

        public override int Remove()
        {
            int count = 0;
            if (DanhSach.Count > 0)
            {
                for (int i = 0; i < DanhSach.Count; i++)
                {
                    DangKyDAO.DangKyDTO = DanhSach[i];
                    if (DangKyDAO.Delete() > 0)
                    {
                        count++;
                    }
                }
            }
            if (count > 0)
            {
                return count;
            }
            return -1;
        }

        public DataTable List(string MaSinhVien)
        {
            return DangKyDAO.List(MaSinhVien);
        }

        public int[] NamHocvaHocKy(string MaSinhVien)
        {
            return DangKyDAO.NamHocvaHocKy(MaSinhVien);
        }

        public DataTable Search(string MaSinhVien, string NamHoc, string HocKy)
        {

            if (string.IsNullOrEmpty(NamHoc))
            {
                NamHoc = "%";
            }
            if (string.IsNullOrEmpty(HocKy))
            {
                HocKy = "%";
            }
            return DangKyDAO.Search(MaSinhVien, NamHoc, HocKy);
        }
    }
}
